// 这里放置的是拉取筛选数据的逻辑方法

import { ref, onMounted } from 'vue'
import { findSubCategoryFilter } from '@/api/category'
import { useRoute } from 'vue-router'
export function useLoadFilterData () {
  const subData = ref(null)
  const route = useRoute()
  async function loadSubData () {
    const res = await findSubCategoryFilter(route.params.id)
    subData.value = res.result
    // 数据结构是一致的  { id, name }
    subData.value.saleProperties.forEach((item) => {
      item.properties.unshift({
        id: null,
        name: '全部'
      })
    })
    // 增加一个字段
    subData.value.saleProperties.forEach(item => {
      item.properties.forEach(i => {
        i.selected = false // false->不选中
      })
    })
  }
  onMounted(() => {
    loadSubData()
  })
  return {
    subData
  }
}
